package com.aruba.recyclerviewapplication;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

public class MainActivity extends AppCompatActivity {
    private RecyclerView rv_father;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        rv_father = findViewById(R.id.rv_father);
        rv_father.setLayoutManager(new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false));
        MyAdpater myAdpater = new MyAdpater(this);
        rv_father.setAdapter(myAdpater);
    }

    class MyAdpater extends RecyclerView.Adapter {
        private Context context;

        public MyAdpater(Context context) {
            this.context = context;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new MyViewHolder(LayoutInflater.from(context)
                    .inflate(R.layout.item_recyclerview, parent, false));
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
            MyViewHolder myViewHolder = (MyViewHolder) holder;
            myViewHolder.rv_son.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.HORIZONTAL, false));
            SonAdapter sonAdapter = new SonAdapter(context);
            myViewHolder.rv_son.setAdapter(sonAdapter);
        }

        @Override
        public int getItemCount() {
            return 6;
        }

        class MyViewHolder extends RecyclerView.ViewHolder {
            public RecyclerView rv_son;

            public MyViewHolder(@NonNull View itemView) {
                super(itemView);
                rv_son = itemView.findViewById(R.id.rv_son);
            }
        }
    }

    class SonAdapter extends RecyclerView.Adapter {
        private Context context;

        public SonAdapter(Context context) {
            this.context = context;
        }

        @NonNull
        @Override
        public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
            return new SonViewHolder(LayoutInflater.from(context).inflate(R.layout.item_son, parent, false));
        }

        @Override
        public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        }

        @Override
        public int getItemCount() {
            return 20;
        }

        class SonViewHolder extends RecyclerView.ViewHolder {
            public SonViewHolder(@NonNull View itemView) {
                super(itemView);
            }
        }
    }
}
